package com.qq2008.game.stzb.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qq2008.game.stzb.jdo.Bag;
import com.qq2008.game.stzb.jdo.Role;
import com.qq2008.game.stzb.mapper.BagMapper;
import com.qq2008.game.stzb.mapper.GoodMapper;
import com.qq2008.game.stzb.utils.PageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/mojie")
public class BagController extends BaseController {

    @Resource
    private GoodMapper goodMapper;

    @Resource
    private BagMapper bagMapper;


    /**
     * 背包道具列表
     */
    @GetMapping(value = "/bag")
    public String bag(Model model, HttpSession session, @RequestParam Map<String, String> map) {
        Role role = getSessionRole(session);
        if (map.size() == 0 || map.get("currentPage").isEmpty()) {
            map.put("currentPage", "1");
        }
        List<Bag> bags = bagMapper.selectList(new LambdaQueryWrapper<Bag>().eq(Bag::getUserId, role.getUserId()));
        model.addAttribute("pageTitle", "背包");
        model.addAttribute("role", role);

        PageUtil pageInfo = new PageUtil(Integer.valueOf(map.get("currentPage")), 5, bags);
        model.addAttribute("bags", pageInfo.getList());
        model.addAttribute("pageInfo", pageInfo);
        return "bag";
    }

}
